1. Fields of the Invention
The present invention relates to processing electronic messages. More particularly, the present invention relates to processing electronic messages out-of-order or in parallel and committing the processed electronic messages in order or out-of-order.
2. Description of the Prior Art
An electronic message refers to any type of data structure exchanged between two parties (e.g., two hardware, two software, hardware and software, etc.) via an electronic communication. The electronic message includes, but is not limited to, an e-mail, an instant message, an audio message, a text message and a facsimile message.
One of key elements of Java Message Service (JMS) is message-driven beans (MDBs). The JMS is a messaging standard that allows applications based on Java® software technology to create, send, receive and read electronic messages. The JMS enables distributed, loosely coupled, reliable and asynchronous communication between an electronic message publisher (i.e., a computing device generating an electronic message) and an electronic message subscriber (i.e., a computing device receiving the electronic message). MDBs are a component that allows Java® applications to process electronic messages asynchronously. MDBs act as a JMS message listener, which is similar to an event listener/detector except it receives electronic messages instead of events. MDBs monitor a queue receiving electronic messages. When an electronic message arrives at the queue, an instance of the MDB is invoked asynchronously to process the electronic message. The MDB instance refers to one or more threads executing the MDB.
Within servers including Java® applications, it is possible to have multiple instances of an MDB processing electronic messages concurrently. The electronic messages are removed from the queue and delivered to the MDB instance(s) in an order in which they arrive at the queue to process the electronic messages in the order.
Thus, in a traditional solution, to preserve a message ordering (i.e., processing electronic messages in the order that they arrive at the queue), the traditional solution implements a sequential logic in the MDB. The sequential logic refers to a counting attribute, which is implemented in an electronic message header. For example, if an electronic message needs to be processed in a sequence, then a message publisher add a sequence number into the electronic message header in the electronic message. The sequence number starts at 0 and is incremented by 1 for each message added by the electronic message publisher. When the electronic messages are delivered to an MDB, the MDB checks the sequence number of a current message in the header, and compares the sequence number of the current message to the sequence number of the last message that was successfully processed. If the sequence number of the current message is 1 greater than the sequence number of the last message processed, then the MDB attempt to process the current message. Otherwise, the current message is rolled back onto the queue that the electronic message came from. Thus, the MDB needs to maintain a record of the last message that was processed. When a new message is delivered to an MDB, the MDB needs to check whether this message has a right sequence number, which equals to the sequence number of a last message +1.
However, the traditional solution is not efficient due to requiring adding a sequence number in an electronic message header and comparing sequence numbers whenever receiving a new message. Furthermore, the traditional solution requires application developers to implement the sequential logic in the MDB, rather than focusing on an actual processing of electronic messages.
Thus, to improve efficiency when processing electronic messages and to remove a necessity of implementing the sequential logic in the MDB, it is desired to provide a method and a system for processing electronic messages out-of-order or in parallel and committing the processed electronic messages in order or out-of-order.